<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of clusterCountEHK2</title>
  <meta name="keywords" content="clusterCountEHK2">
  <meta name="description" content="Find the clusters of connected'values' in the given lattic state s">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">Code</a> &gt; clusterCountEHK2.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for Code&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>clusterCountEHK2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Find the clusters of connected'values' in the given lattic state s</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [c LL F pts]=clusterCountEHK2(s,value) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">Find the clusters of connected'values' in the given lattic state s</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>	</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="LatticeSimulation.html" class="code" title="function [s,cs,LL,F,Energy]=LatticeSimulation(varargin)">LatticeSimulation</a>	Lattice Simulation Model main routine</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function r=properLabel(Sn)</a></li></ul>

<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [c LL F pts]=clusterCountEHK2(s,value)</a>
0002 <span class="comment">%Find the clusters of connected'values' in the given lattic state s</span>
0003 <span class="keyword">if</span> nargin&lt;2
0004     value=-1;
0005 <span class="keyword">elseif</span> length(value)&gt;1
0006   <span class="keyword">for</span> i=1:length(value)
0007       s(s==value(i))=value(1);
0008   <span class="keyword">end</span>
0009   value=value(1);
0010 <span class="keyword">end</span>
0011 Not=value+25;
0012 [r,c1]=size(s);
0013 c=zeros(size(s));
0014 largest_label=0;
0015 LL=zeros(r*c1,1);
0016 periodicBCs=true;
0017 
0018 
0019 <span class="comment">%F=struct('x',zeros(1,r*c1),'y',zeros(1,r*c1),...</span>
0020 <span class="comment">%    'x2',zeros(1,r*c1),'y2',zeros(1,r*c1));</span>
0021 F.x=zeros(r*c1,1);
0022 F.y=F.x;
0023 F.x2=F.x;
0024 F.y2=F.x;
0025 pts=cell(r*c1,1);
0026 neighbor=zeros(4,1);
0027 <span class="keyword">for</span> i=1:r
0028     im1=i-1;   
0029     <span class="keyword">for</span> j=1:c1
0030         jm1=j-1;
0031         <span class="keyword">if</span> s(i,j)==value;
0032 
0033             <span class="keyword">if</span> i==1
0034                 above=Not;
0035             <span class="keyword">else</span>
0036                 above=s(im1,j);
0037             <span class="keyword">end</span>
0038             
0039             <span class="keyword">if</span> j==1
0040                 left=Not;
0041             <span class="keyword">else</span>
0042                 left=s(i,jm1);
0043             <span class="keyword">end</span>
0044 
0045             
0046                 neighbor=[0 0];
0047                 
0048                 <span class="keyword">if</span> above==value
0049                     pl=<a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>(c(im1,j));
0050                    neighbor(1)=pl;
0051                 <span class="keyword">end</span>
0052                 <span class="keyword">if</span> left==value
0053                     neighbor(2)=<a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>(c(i,jm1));
0054                     
0055                 <span class="keyword">end</span>
0056 
0057                
0058                    <span class="keyword">if</span> neighbor(1)&gt;0 || neighbor(2)&gt;0
0059                       
0060                        <span class="keyword">if</span> neighbor(1)==neighbor(2)
0061                            neighbor=neighbor(1);
0062                        <span class="keyword">elseif</span> neighbor(1)&gt;0
0063                            <span class="keyword">if</span> neighbor(2)&gt;0
0064                                neighbor=neighbor(1:2);
0065                            <span class="keyword">else</span>
0066                                neighbor=neighbor(1);
0067                            <span class="keyword">end</span>
0068                        <span class="keyword">else</span>
0069                            neighbor=neighbor(2);
0070                        <span class="keyword">end</span>
0071 
0072                        <span class="comment">%neighbor=unique(neighbor(neighbor&gt;0));</span>
0073                        
0074                        <span class="comment">%[c,LL,F]=mergeClusters(i,j,neighbor,c,LL,F);</span>
0075                        [mn,imn]=min(neighbor);
0076                         
0077                         sumc = 1+sum(LL(neighbor));
0078                         sumx = j+sum(F.x(neighbor));
0079                         sumy = i+sum(F.y(neighbor));
0080                         F.x2(neighbor(imn))=j*j+sum(F.x2(neighbor));
0081                         F.y2(neighbor(imn))=i*i+sum(F.y2(neighbor));
0082                         pts{mn}=[(j-1)*c1+i pts{neighbor}];
0083                         <span class="comment">%Label of labels negative sign points to</span>
0084                         <span class="comment">%'proper label'</span>
0085                         LL(neighbor(neighbor~=mn))=-mn;
0086 
0087 
0088 
0089                         LL(neighbor(imn))=sumc;
0090                         F.x(neighbor(imn))=sumx;
0091                         F.y(neighbor(imn))=sumy;
0092                         c(i,j)=neighbor(imn);            
0093                                   
0094                    <span class="keyword">else</span>
0095                        largest_label=largest_label+1;
0096                         LL(largest_label)=1;
0097                         c(i,j)=largest_label;
0098                         F.x(largest_label)=j;
0099                         F.y(largest_label)=i;
0100                         F.x2(largest_label)=j*j;
0101                         F.y2(largest_label)=i*i;
0102                         pts{largest_label}=(j-1)*c1+i;
0103                    <span class="keyword">end</span>
0104   
0105         <span class="keyword">end</span>
0106     <span class="keyword">end</span>
0107 <span class="keyword">end</span>
0108 <span class="keyword">if</span> periodicBCs
0109 <span class="keyword">for</span> i=1:r
0110     <span class="keyword">if</span> s(i,1)==value &amp;&amp; s(i,c1)==value
0111         s1=<a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>(c(i,1));
0112         s2=<a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>(c(i,c1));
0113         <span class="keyword">if</span> s1&lt;s2
0114             F.x2(s1)=F.x2(s1)+F.x2(s2)-2*c1*F.x(s2)+LL(s2)*c1*c1;
0115             F.y2(s1)=F.y2(s1)+F.y2(s2);
0116             F.y(s1)=F.y(s1)+F.y(s2);
0117             F.x(s1)=F.x(s1)+F.x(s2)-c1*LL(s2);
0118             pts{s1}=[pts{s1} pts{s2}];
0119             LL(s1)=LL(s1)+LL(s2);
0120             LL(s2)=-s1;
0121            
0122         <span class="keyword">end</span>
0123         <span class="keyword">if</span> s2&lt;s1
0124             F.x2(s2)=F.x2(s1)+F.x2(s2)-2*c1*F.x(s2)+LL(s2)*c1*c1;
0125             F.y2(s2)=F.y2(s1)+F.y2(s2);
0126             F.y(s2)=F.y(s1)+F.y(s2);
0127             F.x(s2)=F.x(s1)+F.x(s2)-c1*LL(s2);
0128             pts{s2}=[pts{s1} pts{s2}];
0129             LL(s2)=LL(s2)+LL(s1);
0130             LL(s1)=-s2;
0131         <span class="keyword">end</span>
0132         
0133         
0134     <span class="keyword">end</span>
0135 <span class="keyword">end</span>
0136 
0137 <span class="keyword">for</span> j=1:c1
0138     
0139     <span class="keyword">if</span> s(1,j)==value &amp;&amp; s(r,j)==value
0140         s1=<a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>(c(1,j));
0141         s2=<a href="properLabel.html" class="code" title="function r=properLabel(Sn,LL)">properLabel</a>(c(r,j));
0142         <span class="keyword">if</span> s1&lt;s2
0143             F.x2(s1)=F.x2(s1)+F.x2(s2);
0144             F.y2(s1)=F.y2(s1)+F.y2(s2)-2*r*F.y(s2)+LL(s2)*r*r;
0145             F.y(s1)=F.y(s1)+F.y(s2)-r*LL(s2);
0146             F.x(s1)=F.x(s1)+F.x(s2);
0147             pts{s1}=[pts{s1} pts{s2}];
0148             LL(s1)=LL(s1)+LL(s2);
0149             LL(s2)=-s1;
0150         <span class="keyword">end</span>
0151         <span class="keyword">if</span> s2&lt;s1
0152             F.x2(s2)=F.x2(s1)+F.x2(s2);
0153             F.y2(s2)=F.y2(s1)+F.y2(s2)-2*r*F.y(s2)+LL(s2)*r*r;
0154             F.y(s2)=F.y(s1)+F.y(s2)-r*LL(s2);
0155             F.x(s2)=F.x(s1)+F.x(s2);
0156             pts{s2}=[pts{s1} pts{s2}];
0157             LL(s2)=LL(s2)+LL(s1);
0158             LL(s1)=-s2;
0159         <span class="keyword">end</span>
0160         
0161         
0162     <span class="keyword">end</span>
0163     
0164 <span class="keyword">end</span>
0165 <span class="keyword">end</span>
0166     LL=LL(1:largest_label);
0167     pts=pts(1:largest_label);
0168     
0169     F.x=F.x(1:largest_label);
0170     F.y=F.y(1:largest_label);
0171     F.x2=F.x2(1:largest_label);
0172     F.y2=F.y2(1:largest_label);
0173     F.s=LL(1:largest_label);
0174     F.rs2=F.s.^-2.*((F.s.*F.x2-F.x.*F.x+F.s.*F.y2-F.y.*F.y));
0175     
0176     
0177 <a name="_sub1" href="#_subfunctions" class="code">function r=properLabel(Sn)</a>
0178     r=Sn;
0179     t=r;
0180     t=-LL(t);
0181     <span class="keyword">while</span> t&gt;0
0182         r=t;
0183         t=-LL(t);
0184     <span class="keyword">end</span>
0185 <span class="keyword">end</span>
0186 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Mon 21-May-2012 09:54:18 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>